<template>
  <div>
    <!-- 医院设置列表添加 -->
    医院设置添加
    <el-form label-width="120px">
      <el-form-item label="医院名称">
        <el-input v-model="hospitalSet.hosname" />
      </el-form-item>
      <el-form-item label="医院编号">
        <el-input v-model="hospitalSet.hoscode" />
      </el-form-item>
      <el-form-item label="api基础路径">
        <el-input v-model="hospitalSet.apiUrl" />
      </el-form-item>
      <el-form-item label="联系人姓名">
        <el-input v-model="hospitalSet.contactsName" />
      </el-form-item>
      <el-form-item label="联系人手机">
        <el-input v-model="hospitalSet.contactsPhone" /> </el-form-item
      >……
      <el-form-item>
        <el-button type="primary" @click="saveOrUpdate">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import hospset from "@/api/hospitalSet";
export default {
  data() {
    return {
      hospitalSet: {}
    };
  },
  created() {
    //1 获取路由传过来的id
    if (this.$route.params.id) {
      const id = this.$route.params.id;
      this.getInfo(id);
    }
    //2 根据id查询详情并显示
  },
  methods: {
    save() {
      hospset.save(this.hospitalSet).then(res => {
        this.$message({
          type: "success",
          message: "添加成功!"
        });
        this.$router.push({ path: "/hospitalSet/list" });
      });
    },
    update() {
      hospset.update(this.hospitalSet).then(res => {
        this.$message({
          type: "success",
          message: "修改成功!"
        });
        this.$router.push({ path: "/hospitalSet/list" });
      });
    },
    saveOrUpdate() {
      if (this.hospitalSet.id) {
        this.update();
      } else {
        this.save();
      }
    },
    getInfo(id) {
      hospset.getInfo(id).then(res => {
        this.hospitalSet = res.data;
      });
    }
  }
};
</script>

<style></style>
